<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UCenter Administrator's Control Panel</title>
<link rel="stylesheet" href="/public/images/admincp.css" type="text/css" media="all" />
<link rel="stylesheet" href="/public/images/admin.css" type="text/css" media="all" />
<script src="/public/include/js/formFilter.js" type="text/javascript"></script> 
<meta content="Comsenz Inc." name="Copyright" />
</head>
<body>
<div id="append"></div>
<a class="othersoff" style="float:right;text-align:center" id="header_menu" onclick="headermenu(this)">菜单</a>
<ul id="header_menu_menu" style="display: none">
  <li><a href="#" target="main" class="tabon">近一周登陆纪录</a></li>
</ul>
<script type="text/javascript"> 
	function headermenu(ctrl) {
		ctrl.className = ctrl.className == 'otherson' ? 'othersoff' : 'otherson';
		var menu = document.getElementById('header_menu_body');
		if(!menu) {
			menu = document.createElement('div');
			menu.id = 'header_menu_body';
			menu.innerHTML = '<ul>' + document.getElementById('header_menu_menu').innerHTML + '</ul>';
			var obj = ctrl;
			var x = ctrl.offsetLeft;
			var y = ctrl.offsetTop;
			while((obj = obj.offsetParent) != null) {
				x += obj.offsetLeft;
				y += obj.offsetTop;
			}
			menu.style.left = x + 'px';
			menu.style.top = y + ctrl.offsetHeight + 'px';
			menu.className = 'togglemenu';
			menu.style.display = '';
			document.body.appendChild(menu);
		} else {
			menu.style.display = menu.style.display == 'none' ? '' : 'none';
		}
	}
</script>
<script type="text/javascript">
function switchbtn() {
	$('#srchuserdiv').toggle();
	$('#srchuserdiv').toggleClass('tabcontentcur');
	$('#srchuserbtn').toggleClass('tabcurrent');
			
	$('#adduserdiv').toggle();
	$('#adduserdiv').toggleClass('tabcontentcur');
	$('#adduserbtn').toggleClass('tabcurrent');
}
</script>
<div class="container">
  <div class="hastabmenu">
    <ul class="tabmenu">
      <li id="srchuserbtn" class="tabcurrent"><a href="#" onclick="switchbtn()">搜索用户</a></li>
      <li id="adduserbtn"><a href="#" onclick="switchbtn()">添加用户</a></li>
    </ul>
    <div id="adduserdiv"  class="tabcontent" style="display:none;">
      <form action="/admin/user/create" method="post"    id="addUserForm"  onsubmit="return $.formValidator.pageIsValid('1')">
        <table width="100%">
          <tr>
            <td>用户名:</td>
            <td><input type="text" name="addname" id="addname" class="txt" /></td>
            <td>密码:</td>
            <td><input type="password" name="addpassword" id="addpassword" class="txt" /></td>
			<td>确认密码:</td>
            <td><input type="password" id="addpassword1" class="txt" /></td>
            <td>&nbsp;</td>
          </tr>
		  <tr>
			 <td>角色:</td>
            <td>
				<select name="addrole"  id="addrole1">
					<!--<option value="">请选择角色</option>-->
					<?php 
						$roles = $this->user_roles->fetchAll(null , 'id desc');
						foreach($roles as $role){
					?>
					<option value="<?php echo $role->name;?>"><?php echo $role->name;?></option>
					<?php
						}
					?>
				</select>
			</td>
			<td>Email:</td>
            <td><input type="text" name="addemail" id="addemail" class="txt" /></td>
             <td colspan="4" id="info">&nbsp;</td>
            <td><input type="submit" value="提 交"  class="btn" id="submit_add"/></td>
		  </tr>
        </table>
      </form>
    </div>
	
	
	
	
    <div id="srchuserdiv" class="tabcontentcur">
      <form action="/admin/user" method="post">
        <table width="100%">
          <tr>
            <td>用户名:</td>
            <td><input type="text" name="username" value="" class="txt" /></td>
            <td>Email:</td>
            <td><input type="text" name="email" value="" class="txt" /></td>
            <td rowspan="2"><input type="submit" value="提 交" class="btn" /></td>
          </tr>
          <tr>
            <td>注册IP:</td>
            <td ><input type="text" name="ip" value="" class="txt" /></td>
			<td>角色:</td>
            <td colspan="2">
				<select name="role">
					<option value="">请选择角色</option>
					<?php 
						$roles = $this->user_roles->fetchAll();
						foreach($roles as $role){
					?>
					<option value="<?php echo $role->name;?>"><?php echo $role->name;?></option>
					<?php
						}
					?>
				</select>
			</td>
          </tr>
        </table>
      </form>
    </div>
  </div>
  
  
  <br />
  <h3>用户列表</h3>
  <div class="mainbox">
    <form action="/admin/user/delete-user" onsubmit="return confirm('该操作不可恢复，您确认要删除这些用户吗？');" method="post">
      <input type="hidden" name="formhash" value="92809f92222c11a1">
      <table class="datalist fixwidth"  >
        <tr>
          <th><input type="checkbox" class="checkbox" onclick="checkall()" id="chkall" name="chkall">
            <label for="chkall">删除</label></th>
          <th>用户名</th>
          <th>Email</th>
          <th>注册日期</th>
          <th>注册IP</th>
		  <th>当前角色</th>
          <th>编辑</th>
        </tr>
		<?php
			$users = $this->users;
			if(users){
				//while($this->users){
				foreach($users as $user){
		?>
        <tr>
          <td class="option">
			<?php echo '<input type="checkbox" name="delete['.$user->id.']" value="1" class="checkbox" />'; ?>
		  </td>
          <td> <strong><?php echo $user->username; ?></strong></td>
          <td><?php echo $user->email; ?></td>
          <td><?php echo date('Y-m-d',$user->register_date); ?></td>
          <td><?php echo $user->ip; ?></td>
		   <td><?php echo $user->role; ?></td>
          <td>
          		<?php echo '<a href="/admin/user/edit/id/'.$user->id.'">编辑</a>'; ?>
		  </td>
        </tr>
  		<?php 
				}
			} 
		?>
        <tr class="nobg">
          <td><input type="submit" value="提 交" class="btn" /></td>
          <td class="tdpage" colspan="7"></td>
        </tr>
      </table>
    </form>
  </div>
</div>
</body>
</html>
<script type="text/javascript"> 

$(function(){  
	//dump($("#addUserForm"));
	$.formValidator.initConfig({autotip:true,tidymode:true,onerror:function(msg){alert(msg)}});
	
	$("#addname").formValidator({onshow:"请输入用户名,只有输入\"maodong\"才是对的",onfocus:"用户名至少6个字符,最多20个字符",oncorrect:"该用户名可以注册"}).inputValidator({min:6,max:20,onerror:"你输入的用户名非法,请确认"}).regexValidator({regexp:"username",datatype:"enum",onerror:"用户名格式不正确"})
	    .ajaxValidator({
		    type : "get",
			url : "/admin/user/ajax-username",
			success : function(data){	
	            if( data == "1" )
				{
	                return true;
				}
	            else
				{
	                return false;
				}
			},
			buttons: $("#submit_add"),
			error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
			onerror : "该用户名不可用，请更换用户名",
			onwait : "正在对用户名进行合法性校验，请稍候..."
		}).defaultPassed();
	
	$("#addpassword").formValidator({onshow:"请输入密码",onfocus:"密码不能为空",oncorrect:"密码合法"}).inputValidator({min:1,onerror:"密码不能为空,请确认"});
	$("#addpassword1").formValidator({onshow:"请输入重复密码",onfocus:"两次密码必须一致哦",oncorrect:"密码一致"}).inputValidator({min:1,onerror:"重复密码不能为空,请确认"}).compareValidator({desid:"addpassword",operateor:"=",onerror:"2次密码不一致,请确认"});
	$("#addemail").formValidator({onshow:"请输入邮箱",onfocus:"邮箱至少6个字符,最多100个字符",oncorrect:"恭喜你,你输对了",defaultvalue:"@"}).inputValidator({min:6,max:100,onerror:"你输入的邮箱长度非法,请确认"}).regexValidator({regexp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onerror:"你输入的邮箱格式不正确"});
	
	
   /*Show Css-Control*/
   $('.datalist tr:even:not(.nobg)').addClass('alt');
   $('.datalist tr:not(.nobg)').hover(function(){
   			$(this).toggleClass('over')
   		},function(){
			$(this).toggleClass('over')
		}
   );
   
   
});
</script>
